package test.layouts;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.ToggleButton;

public class LayoutsActivity extends Activity {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		setClicks();
	}

	public void setClicks() {
		final Button btnAceptar = (Button) findViewById(R.id.BtnAceptar);
		final ToggleButton btnOnOff = (ToggleButton) findViewById(R.id.BtnOnOff);
		final ImageButton btnImage = (ImageButton) findViewById(R.id.BtnImage);
		final EditText txtMensaje = (EditText) findViewById(R.id.TxtMensaje);
		final ImageView imagen1 = (ImageView) findViewById(R.id.Imagen1);
		final CheckBox chk1 = (CheckBox) findViewById(R.id.chk1);
		final String[] datos =
		    new String[]{"Elem1","Elem2","Elem3","Elem4","Elem5"};
		final ArrayAdapter<String> adaptadorList = new ArrayAdapter<String>(this, 
				android.R.layout.simple_list_item_1, datos);
		btnAceptar.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				txtMensaje.setText("Aceptar");
				setContentView(R.layout.layout1);
				//ListView
				final ListView lstOpciones = (ListView) findViewById(R.id.LstOpciones);
				lstOpciones.setAdapter(adaptadorList);
			}
		});
		btnOnOff.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (btnOnOff.isChecked()) {
					txtMensaje.setText("Sussan");
					imagen1.setImageResource(R.drawable.susan);
				} else {
					txtMensaje.setText("woow");
					imagen1.setImageResource(R.drawable.woow);
				}
			}
		});
		btnImage.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				txtMensaje.setText("Imagen");
				imagen1.setImageResource(R.drawable.ic_launcher);
			}
		});
		chk1.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				if (isChecked) {
					chk1.setText("Checkbox marcado!");
				} else {
					chk1.setText("Checkbox desmarcado!");
				}
			}

		});

		// ComboBox
		ArrayAdapter<String> adaptador = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_item, datos);
		final Spinner cmbOpciones = (Spinner) findViewById(R.id.CmbOpciones);
		adaptador
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		cmbOpciones.setAdapter(adaptador);
		cmbOpciones
				.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
					public void onItemSelected(AdapterView<?> parent,
							android.view.View v, int position, long id) {
						txtMensaje.setText("Seleccionado: " + datos[position]);
					}

					public void onNothingSelected(AdapterView<?> parent) {
						txtMensaje.setText("");
					}
				});
	}
}